<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='UTF-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title></title>
  <script type='text/javascript' src='js/vue.js'></script>
</head>

<body>
  <div id='app'>
    <div>
      ========================
      <broa></broa>
      <brob></brob>
    </div>
  </div>
  <script type='text/javascript'>
    // 建立公共仓库
    let eventBus = new Vue();

    var broa = {
      data() {
        return {
          msga: '这是兄弟元素a',
          msgb: ''
        }
      },
      template: `
        <div @click="toBrob"> {{ msga + '======' + msgb }} </div>
      `,
      methods: {
        toBrob() {
          eventBus.$emit('broa', this.msga)
        }
      },
      created() {
        eventBus.$on('brob', val => {
          this.msgb = val
        })
      },
    }
    var brob = {
      data() {
        return {
          msga: '',
          msgb: '这是兄弟元素b'
        }
      },
      template: `
        <div @click="toBrob"> {{ msgb + '======' + msga }} </div>
      `,
      mounted() {
        eventBus.$on('broa', val => {
          console.log(val)
          this.msga = val;
        })
      },
      methods: {
        toBrob() {
          eventBus.$emit('brob', this.msgb)
        }
      },
    }
    var vm = new Vue({
      el: '#app',
      data: {

      },

      components: {
        broa,
        brob
      }
    });
  </script>
</body>

</html>